package com.yuhang.demo.controller;

import com.yuhang.demo.dto.request.DrugRelationAddRequest;
import com.yuhang.demo.dto.request.DrugRelationUpdateRequest;
import com.yuhang.demo.dto.response.Result;
import com.yuhang.demo.service.RuleDrugRelationService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/drug-relation")
public class RuleDrugRelationController {

    @Autowired
    private RuleDrugRelationService drugRelationService;

    public RuleDrugRelationController(RuleDrugRelationService drugRelationService) {
        this.drugRelationService = drugRelationService;
    }

    /**
     * 新增药品关联
     */
    @PostMapping("/add")
    public Result<Long> addDrugRelation(@Valid @RequestBody DrugRelationAddRequest request) {
        return drugRelationService.addDrugRelation(request);
    }

    /**
     * 更新药品关联
     */
    @PutMapping("/update")
    public Result<Boolean> updateDrugRelation(@Valid @RequestBody DrugRelationUpdateRequest request) {
        return drugRelationService.updateDrugRelation(request);
    }

    /**
     * 删除药品关联
     */
    @DeleteMapping("/delete/{id}")
    public Result<Boolean> deleteDrugRelation(@PathVariable Long id) {
        return drugRelationService.deleteDrugRelation(id);
    }

    /**
     * 根据规则ID分页查询药品关联列表
     */
    @GetMapping("/page")
    public Result<?> getDrugRelationPage(@RequestParam Long ruleId,
                                         @RequestParam Integer pageNum,
                                         @RequestParam Integer pageSize) {
        return drugRelationService.getDrugRelationPage(ruleId, pageNum, pageSize);
    }
}
